//koa
const Koa = require('koa')
const Router = require('koa-router')
const app = new Koa()
const router = new Router()
router.get('/',(ctx,next) => {
	ctx.body = {
		code : 200,
		preson:{
			name:'哈哈哈'
		}
	}
})

//首页初始数据
let indexData = require('./datas/index.json')
router.get('/getIndexData',(ctx,next)=>{
	ctx.body={
		code:200,
		indexData
	}
})


// 主页导航页面数据
let indexCateList = require('./datas/indexCateList.json')
router.get('/getindexCateList', async (ctx, next) => {
	// 生成的H5应用存在跨域问题，通过CORS设置跨域配置
	ctx.set('Access-Control-Allow-Origin', '*')
	await new Promise(resolve => setTimeout(() => resolve(),2000))
	ctx.body = indexCateList;
});

// 分类页面数据 
let cateGoryData = require('./datas/categoryDatas.json');
router.get('/getCategoryDatas', async (ctx, next) => {
	ctx.body = {
		code: 200,
		data: cateGoryData
	};
});




app.use(router.routes())
.use(router.allowedMethods())
// 监听端口
app.listen('3001',err=>{
	if(err){
		console.log('服务器启动失败,错误信息为:',err)
		return
	}
	console.log('服务器启动成功,地址为:http://localhost:3001')
})